<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cetak OR</title>
<?php $this->load->helper('HTML');
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
</head>
<?php

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=print_or_manager.xls");
header("Pragma: no-cache");
header("Expires: 0");

?>
<body>
<table width="800" align="center" class="detail">
	<tr class="detail2">
   	  <td align="center">
        <table width="800" align="center" class="detail">
        <tr class="detail2">
          <td width="440" rowspan="4" valign="top"><img src="<?php echo base_url();?>images/logo.jpg" />&nbsp;</td>
          <td width="41">&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td width="41">&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3" >LAPORAN OR CM <?php echo $nama_bulan;?></td>
          </tr>
        <tr>
            <td class="detail2" align="left">NAMA</td>
			<td>:</td>
            <td align="left"><?php echo $data_omset[0]->strnama_dealer;?>&nbsp;</td>
        </tr>
            <tr>
            <td class="detail2">UNIT BARU</td>
                <td><!-- unit baru -->&nbsp;</td>
				<td>&nbsp;</td>
        </tr>
		<tr>
            <td class="detail2">Mother Mgr</td>
                <td><!-- nama mother -->&nbsp;</td>
				<td><!-- nama mother -->&nbsp;</td>
        </tr>
		<tr>
            <td class="detail2">Unit</td>
			<td>:</td>
                <td><?php echo $data_omset[0]->strnama_unit; ?>&nbsp;</td>
	    </tr>
		<tr>
            <td class="detail2">Cabang</td>
			<td>:</td>
                <td><?php echo $data_omset[0]->strnama_cabang; ?>&nbsp;</td>
        </tr>
		<tr>
            <td class="detail2">Periode CM</td>
			<td>:</td>
                <td><?php echo $nama_bulan_pengejaran." - ".$nama_bulan;?>&nbsp;</td></td>
        </tr>
		<tr>
            <td colspan="2"class="detail2">Total Sales</td>
                <td><!-- sales -->&nbsp;</td></td>
        </tr>
    	</table>
	</td>
    <tr>
	<tr><th>BULAN CM</th><td><!-- bulan --></td></tr>
	<tr><td>Penjualan Pribadi</td>
	<td><?php echo $data_omset[0]->total_omset;?></td></tr>
	<tr><td>Rekrut</td><td><!-- Rekrut --></td></tr>
	<tr><td>Unit Sales</td><td><!-- Unit sales --></td></tr>
    	<td align="center">
        	<table width="800" border="1" align="center"  class="detail">
			<tr class="detail2">
                    <th width="89">NAMA</th>
                    <th width="113">Omset 20%</th>
                    <th width="113">Omset 10%</th>
                    <th width="95">Harga Dealer</th>
                    <th width="26">OR 3%</th>
                    <th width="65">PPH 5%</th>
					<th>Terima</th>
			</tr> 
			<?php 			
			$temp	=	array();
			$dataK	=	array();
			$i	=	0;
				$tot20	=	0;
				$tot10	=	0;
				$total	=	0;
				$or3	=	0;
				$pph	=	0;
				$terima	=	0;
				
			foreach($data_omset as $rok){
				if(!empty($rok->omset20)){
						$temp[0] = $rok->omset20;
					}else{
						$temp[0] = 0;
					}
					if(!empty($rok->omset10)){
						$temp[1] = $rok->omset10;
					}else{
						$temp[1] = 0;
					}
					$tot20	=	$tot20 + $temp[0];
					$tot10	=	$tot10 + $temp[1];
					
					$temp[2]	=	($temp[0] * 0.8) + ($temp[1] * 0.9);
					$total = $total + $temp[2];
					
					$temp[3]	=	($temp[2] * 0.03);
					$or3	=	$or3	+	$temp[3];
					
					$temp[4]	=	($temp[3] * 0.05);
					$pph	=	$pph	+	$temp[4];
					
					$temp[5]	=	$temp[3]-$temp[4];
					$terima	=	$temp[5] + $terima;
					echo "<tr>";
					echo "<td>".$rok->strnama_dealer."</td>";
					echo "<td>".$temp[0]."</td>";
					echo "<td>".$temp[1]."</td>";
					echo "<td>".$temp[2]."</td>";
					echo "<td>".$temp[3]."</td>";
					echo "<td>".$temp[4]."</td>";
					echo "<td>".$temp[5]."</td>";
					echo "</tr>";
			}
				foreach($data_anak as $row){
					$dataK = $this->Ranting_model->rekursif_pracm($row->strkode_dealer,$bulan,$temp_bulan);
				}
				//echo "name : ".$data[0]['strnama_dealer'];
				if(!empty($dataK)){
					for($i = 0; $i<sizeof($data);$i++){
						if(!empty($dataK[$i]['intomset20'])){
							$temp[0] = $dataK[$i]['intomset20'];
						}else{
							$temp[0] = 0;
						}
						if(!empty($dataK[$i]['intomset10'])){
							$temp[1] = $dataK[$i]['intomset10'];
						}else{
							$temp[1] = 0;
						}
						$tot20	=	$tot20 + $temp[0];
						$tot10	=	$tot10 + $temp[1];
						
						$temp[2]	=	($temp[0] * 0.8) + ($temp[1] * 0.9);
						$total = $total + $temp[2];
						
						$temp[3]	=	($temp[2] * 0.03);
						$or3	=	$or3	+	$temp[3];
						
						$temp[4]	=	($temp[3] * 0.05);
						$pph	=	$pph	+	$temp[4];
						
						$temp[5]	=	$temp[3]-$temp[4];
						$terima	=	$temp[5] + $terima;
						echo "<tr>";
						echo "<td>".$data[$i]['strnama_dealer']."</td>";
						echo "<td>".$temp[0]."</td>";
						echo "<td>".$temp[1]."</td>";
						echo "<td>".$temp[2]."</td>";
						echo "<td>".$temp[3]."</td>";
						echo "<td>".$temp[4]."</td>";
						echo "<td>".$temp[5]."</td>";
						echo "</tr>";
					}
				}
				//$tot20 = 0;
				//$tot10	=	0;
				foreach($data_anak as $row){
					$tot20 += $this->Ranting_model->rekrusifomset_ver2($row->strkode_dealer,$bulan,$temp_bulan,"omset20");
					$tot10 += $this->Ranting_model->rekrusifomset_ver2($row->strkode_dealer,$bulan,$temp_bulan,"omset10");
				}
				$total	=	($tot20 * 0.8) + ($tot10 * 0.9);
				$or3	=	($total* 0.03);
				$pph	=	($or3 * 0.05);
				$terima	=	$or3 - $pph;
			?>
                <tr class="detail">
                    <td align="center">TOTAL</td>
                  	<td align="center"><?php echo "Rp. ".number_format($tot20,2 , ',' , '.');?></td>
                    <td align="center"><?php echo "Rp. ".number_format($tot10,2 , ',' , '.');?></td>
                    <td align="center"><?php echo "Rp. ".number_format($total,2 , ',' , '.');?></td>
                    <td align="center"><?php echo "Rp. ".number_format($or3,2 , ',' , '.');?></td>
                    <td align="center"><?php echo "Rp. ".number_format($pph,2 , ',' , '.');?></td>
                    <td align="center"><?php echo "Rp. ".number_format($terima,2 , ',' , '.');?></td>
                </tr>
      </table>      </td>
    </tr>
                <tr>
                	<td align="center"><table width="800" align="center" class="detail">
                        <tr>
                          <td colspan="6" align="right">&nbsp;</td>
                        </tr>
                        <tr class="detail2">
						  <td align="center">DIBUAT OLEH</td>
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td align="center">DIPERIKSA OLEH</td>
                          <td>&nbsp;</td>
						  <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td colspan="6" align="right">&nbsp;</td>
                        </tr>
                        <tr>
                          <td colspan="6" align="right">&nbsp;</td>
                        </tr>
                        <tr>
                          <td align="center">(....................)</td>
                          <td>&nbsp;</td>
                         <td>&nbsp;</td>
                         <td align="center">(....................)</td>
                          <td>&nbsp;</td>
                         <td>&nbsp;</td>
						</tr>
                      </table></td>
  </tr>
</table>
</body>
</html>